<style type="text/css">
	.red-star { color:#FF0000; }	
</style>
<div id='panel' style="width:950px;">
<table width="100%" border="0" class="signin_bg">
  <tr>
  	
	<td>
	
	<div class="signin_out">
	<a name="sign" id="sign"></a>
	<div class="signin_top">&nbsp;</div>
	<div class="signin_repeat">
	
		<div class="signin_txt" style=" margin:0px 0px 20px 0px;"><div class="signin_img">&nbsp;</div></div>
	  
		<div class="fulldiv">
		<p><b>Welcome Back!</b></p><br/><br/>
	<?php
		if($_SESSION['user_id_sess']!="" && $_SESSION['user_name']!="" && $_SESSION['user_type_sess']!="") {
			echo "<script type='text/javascript'> window.location='index.php'; </script>";
		}			
		
		if($_COOKIE['swapen_id']!="" && $_COOKIE['swapen_name']!="" && $_COOKIE['swapen_type']!="") {
			session_start();
			$_SESSION['user_id_sess']=$_COOKIE['swapen_id'];
			$_SESSION['user_name']=$_COOKIE['swapen_name'];	
			$_SESSION['user_type_sess']=$_COOKIE['swapen_type'];		
			$_SESSION['user_status']=$_COOKIE['swapen_user_status'];	
			$_SESSION['user_email']=$_COOKIE['swapen_user_email'];		
			if($_SESSION['user_id_sess']!="" && $_SESSION['user_name']!="" && $_SESSION['user_type_sess']!="" && $_SESSION['user_status']!="") {
				echo "<script type='text/javascript'> window.location='index.php'; </script>";
			}				
		}
		else {
			
			?>
				
	<?php
					require_once "includes/config.php";
					if(isset($_POST['smtSignin']))
					{
					   $username=$_POST['username'];
					   $password=$_POST['password'];
					   $chk=$_POST['chk'];
						
						$sqlSelUser="SELECT * FROM tbl_users where status!=5 and username='".$_POST['username']."' and password='".$_POST['password']."'";
						$rstSelUser=mysql_query($sqlSelUser) or die(mysql_query());
						$numSelUser=mysql_num_rows($rstSelUser);			
						
						if($numSelUser>0) {						
							$rowSelUser=mysql_fetch_array($rstSelUser);
							$userId=$rowSelUser['user_id'];
							$userType=$rowSelUser['user_type'];
							$sellingStatus=$rowSelUser['selling_status'];
							$userStatus=$rowSelUser['status'];
							$userEmail=$rowSelUser['email'];
							if($userStatus==3)
							{
								$err="Your account is on hold, please contact us for more information";
							}
							else if($userStatus==4)
							{
								$err="Your Account has been placed on the inactive list, please contact Swapen Support";
							}
							else
							{
								session_start();
								$_SESSION['user_id_sess']=$userId;
								$_SESSION['user_type_sess']=$userType;
								$_SESSION['user_name']=$_POST['username'];
								$_SESSION['user_status']=$userStatus;
								$_SESSION['user_email']=$userEmail;
								setcookie("swapen_type1", $userType, time()+3600*24);
//								if($_POST['remember'])
//								{
//									setcookie("swapen_id", $userId, time()+3600*24);
//									setcookie("swapen_name", $_POST['username'], time()+3600*24);
//									setcookie("swapen_type", $userType, time()+3600*24);
//									setcookie("swapen_user_status", $userStatus, time()+3600*24);
//									setcookie("swapen_user_email", $userEmail, time()+3600*24);
//									
//								}

		  if($chk=='Yes')
		  {
			 setcookie("myusername", $username, time()+ (3600*24*365));
			 setcookie("mypassword", $password, time()+ (3600*24*365));
			 setcookie("rem", $chk, time()+ (3600*24*365));
		  }
		  else
		  { 
			setcookie("myusername", "", time()- 3600);
			setcookie("mypassword", "", time()- 3600);
			setcookie("rem", "", time()-3600);
		  }

								if($_SESSION['user_id_sess']!="" && $_SESSION['user_name']!="" && $_SESSION['user_type_sess']!="") {
									
									if(!empty($_SESSION['viewcart']))
									{
									   echo "<script type='text/javascript'> window.location='index.php?cart' </script>";							
									}
									if($_GET['url']!="") {
										echo "<script type='text/javascript'> window.location='index.php?mySwapen".$_GET['url']."'; </script>";
									}
									else {
										echo "<script type='text/javascript'> window.location='index.php?mySwapen'; </script>";
									}
								}						
							}
						}
						else { $err='Invalid user name and password.'; }				
					
					}
					
				?>
						
				<form name="frmSignin" id="frmSignin" method="post" action="">
				<?php
					if(!empty($err)){
						echo "<div class='red-star'>".$err."</div>";
					}
					else if(!empty($_GET['url'])) {
						if($_GET['url']=="bargain") {
							echo "<div class='red-star'> Sign in to Place your bargain. </div>";						
						}
						elseif($_GET['url']=="wlist") {
							echo "<div class='red-star'> Sign in to Access your wishlist. </div>";						
						}
						elseif($_GET['url']=="mylist") {
							echo "<div class='red-star'> Sign in to Access your listings. </div>";						
						}
						elseif($_GET['url']=="sell") {
							echo "<div class='red-star'> Sign in to sell your product. </div>";						
						}
						elseif($_GET['url']=="profile") {
							echo "<div class='red-star'> Sign in to access your profile. </div>";						
						}
						else {	}
					}
				?>
				<table border="0" width="100%" align="center">
					<tr style="margin:5px 0px 5px 0px;">
						<td width="35%" height="30">Username</td>
						<td width="65%">
						
						<input class="inputbg" type="text" name="username" id="username" style="width:210px;" value="<?php if($_COOKIE['myusername']!="") { echo $_COOKIE['myusername']; } ?>" />
						
						</td>
					</tr>
					<tr style="margin:5px 0px 5px 0px;">
						<td height="30">Password</td>
						<td>
						
						<input class="inputbg" type="password" name="password" id="password" style="width:210px;" value="<?php if($_COOKIE['mypassword']!="") { echo $_COOKIE['mypassword']; } ?>" />
						
						</td>
					</tr>
					<tr style="margin:5px 0px 5px 0px;">
						<td height="30">&nbsp;</td>
						<td>
						
						<a href="index.php?forgotUsername" class="bluelink">Forgot username</a> or
						<a href="index.php?forgotPassword" class="bluelink">password</a>
						</td>
					</tr>
					<tr>
						<td height="30">Remember Me Today</td>
						<td><input type="checkbox" name="chk" id="chk" <?php if($_COOKIE['rem']=="Yes") { echo "checked"; } ?> value="Yes" /></td>
					</tr>
					<tr style="margin:5px 0px 5px 0px;">
						<td height="30">&nbsp;</td>
						<td><input type="submit" value="Sign In" name="smtSignin" id="smtSignin" class="button" /></td>
					</tr>		
				</table>
				</form>
			
	<?php } ?>
		</div>
	
	</div>
	<div class="signin_bot">&nbsp;</div>
	
	</div>
	
	<div class="signrgt_out">
		
		<div class="signrgt_top">&nbsp;</div>
		<div class="signrgt_repeat">
			<table border="0" width="100%" align="center">
			
			<tr>
			<td class="blue_big">
			<span style="margin:15px 0px 10px 0px; float:left; width:100%;">Don't have an account yet?</span>
			</td>
			</tr>
			
			<tr>
			<td class="black_big"> <span style="margin:15px 0px 25px 0px; float:left;  width:100%;">Start making things happen</span></td>
			</tr>
			
			<tr>
			<td> 
			<span style="margin:15px 0px 15px 0px; float:left;  width:100%;">
			<input type="button" value="Register" onclick="window.location='index.php?signup'" name="" id="" class="button" />
			</span>
			</td>
			</tr>
			
			<tr>
			<td class="blue_big"><span style="margin:15px 0px 15px 0px; float:left; width:100%;">Benefits of joining</span></td>
			</tr>
			
			<tr>
			<td class="black_big">
			<?php
			//echo "hi".$_COOKIE['swapen_type1'];
			if($_COOKIE['swapen_type1']==1 || $_COOKIE['swapen_type1']==2)
			{
			?>
			<span style="margin:15px 0px 15px 0px; float:left; line-height:30px; width:100%; color:#4f4f4f;">
			Sell Products FOR Other Users<br/>
			Have YOUR Products Sold for YOU<br/>
			Verified Local Pick-Up<br/>
			Custom Wanted Items List <br/>
			All Our Merchant are <font style="color:#24299b;">Verified</font><br/>
			And Many Others
			</span>
			<?php
			}
			else if($_COOKIE['swapen_type1']==3)
			{
			?>
			<span style="margin:15px 0px 15px 0px; float:left; line-height:30px; width:100%; color:#4f4f4f;">
			Have YOUR Products Sold for YOU<br/>
			Verified Local Pick-Up<br/>
			Custom Wanted Items List <br/>
			Free Classified Ads! <br/>
			Search for Wholeseller Products. <br/>
			And Many Others
			</span>
			<?php
			}
			else if($_COOKIE['swapen_type1']==5)
			{
			?>
			<span style="margin:15px 0px 15px 0px; float:left; line-height:30px; width:100%; color:#4f4f4f;">
			First Year FREE!<br/>
			Acess Directly To Merchants<br/>
			Merchants Acess Your Inventory<br/>
			Search Through Wanted Items List<br/>
			Upload ALL Your items at Once<br/>
			And Many Others
			</span>
			<?php
			}
			else
			{
			?>
			<span style="margin:15px 0px 15px 0px; float:left; line-height:30px; width:100%; color:#4f4f4f;">
			Sell Products FOR Other Users<br/>
			Have YOUR Products Sold for YOU<br/>
			Verified Local Pick-Up<br/>
			Custom Wanted Items List <br/>
			All Our Merchant are <font style="color:#24299b;">Verified</font><br/>
			And Many Others
			</span>
			<?php
			}
			?>
			<div class="signin_arrow">&nbsp;</div>
			</td>
			</tr>

			
			</table>
		</div>
		<div class="signrgt_bot">&nbsp;</div>
		
	</div>
	
	</td>
  </tr>
</table>	
</div>	 